<?php
$err = isset($_GET['error']) ? $_GET['error'] : null ;

require'../clases/sesiones.php';
$objses = new Sesion();
$objses->iniciar();

$user = isset($_SESSION['user']) ? $_SESSION['user'] : null ;
$profile = $_SESSION['idprofile'];
if($user == ''){
    header('Location: ../index.php?error=2');
}else{
}
?>
<?php
    require'../clases/modulo.php';
    require'../clases/config.php';
    require'../clases/usuarios.php';
    require'../clases/acciones.php';
    require '../clases/nivel_acceso.php';
    require '../clases/modulo_nivel_acceso.php';
?>
<!DOCTYPE html>
<html lang = "es">
    <head>
        <title>Consultar niveles de acceso</title>
        <meta charset = "utf-8" />
        <link rel="stylesheet" type="text/css" href="../css/intranet.css">
        <link rel="stylesheet" type="text/css" href="css/forms.css">
        <script src="../js/jquery.min.js"></script>
        <script src = "../js/mis-contactos.js"></script>
        <script src="js/jquery-1.9.1.js" type="text/javascript"></script>
        <script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>
        <script src="js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="js/valores.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                
                $('#habilitarAhora').click(function() {
                    return !$('#deshabilitados option:selected').remove().appendTo('#habilitados');
                });
                $('#deshabilitarAhora').click(function() {
                    return !$('#habilitados option:selected').remove().appendTo('#deshabilitados');

                });
            });
        </script>
    </head>
    <body>
        <header id="header">
            <hgroup>
                <h1 class="site_title"><a href="index.html">Intranet Renacer</a></h1>
            </hgroup>
                <?php 
                if($err==1){
                    echo '<div class="error">Usted no tiene los privilegios para ingresar a la URL solicitada, Acceso Denegado</div>';
                }
             ?>
        </header>
        <section id="secondary_bar">
            <div class="user">
                <p><?php echo $_SESSION['name'] . " " . $_SESSION['apep'];?> (<a style="text-decoration: underline; color: blue;" href="log_out.php">Salir</a>)</p>
                <!-- <a class="logout_user" href="#" title="Logout">Logout</a> -->
            </div>
            </section>
            <aside id="sidebar">
                <?php   
                        $con = new Coneccion();
                        $objUsuario = new Usuario();
                        $bd = $con->conectar_bd();
                        $objUsuario->smenu();
                        $con->desconectar_bd($bd);
                ?>
            </aside>
            <section id="main" class="column">
                <article class="module width_full">
                    <form class="contact_form" method="POST" action="" name="consultar_modulos">
                        <ul>
                            <li>
                                <label for="search">Buscar por nombre:</label>
                                <select name="search" required>
                                                                <option value="">-- Seleccione un nivel de acceso --</option>
                                                                    <?php
                                                                        $con = new Coneccion();
                                                                        $bd = $con->conectar_bd();
                                                                        $na = new NivelAcceso();
                                                                        $mostrar_na = $na->mostrar_na();
                                                                            while ($row=mysql_fetch_array($mostrar_na)) {
                                                                            ?>
                                                                                <option value="<?php echo $row['id_nivelacceso']; ?>"><?php echo $row['nombre_acceso']; ?></option>
                                                                                 <?php
                                                                                    }
                                                                        $con->desconectar_bd($bd);
                                                                                ?>
                                </select>
                                <button name="submit" class="submit" >Buscar </button>
                            </li>
                        </ul>
                    </form>
                    <br />
                        <?php
                            if(isset($_POST['submit'])){

                                ?>
                                <input type="text" id="variable" name="variable" value="<?php echo $_POST['search']; ?>" readonly hidden/>
                                <form method="POST" action="" name="pasar_valores">
                                    <div style=" margin: 0 auto; width: 100%;text-align:center">
                                             <h2>Habilitados</h2>
                                             <select id="habilitados" style="width: 60%;margin:0 auto;border:1px solid #ccc;padding:10px;border-radius:10px 0 0 10px;" name="habi" size="9">
                                        <?php
                                                        $con = new Coneccion();
                                                        $bd = $con->conectar_bd();
                                                        $modulo= new Modulo();
                                                        $mod_mna = $modulo->cons_mod_na($_POST['search']);
                                                        while ($row=mysql_fetch_array($mod_mna)) {    
                                                    ?>
                                                            <option value="<?php echo $row['id_modulo']; ?>"><?php echo $row['nombre_modulo']; ?></option>
                                                    <?php
                                                    }
                                                    $con->desconectar_bd($bd);
                                        ?>
                                        </select>
                                    </div>
                                    <div style="width: 100%; text-align:center">
                                            <input type="button" class="buttonup" id="deshabilitarAhora" value="deshabilitar" onclick="buscarD()" />
                                            <input type="button" class="buttondown" id="habilitarAhora" value="habilitar" onclick="buscarH()" />
                                    </div>
                                    <div id="mensaje">

                                    </div>
                                    <div style="width:100%; text-align:center">
                                        <h2>Deshabilitados</h2>    
                                        <select id="deshabilitados" style="width: 60%;margin:0 0 50px 0;border:1px solid #ccc;padding:10px;border-radius:10px 0 0 10px;" name="deshabi" size="9">
                                        <?php
                                                        $con = new Coneccion();
                                                        $bd = $con->conectar_bd();
                                                        $modulo= new Modulo();
                                                        $mod_mna = $modulo->cons_mod_nona($_POST['search']);
                                                        
                                                        while ($row=mysql_fetch_array($mod_mna)) {    
                                                    ?>
                                                            <option value="<?php echo $row['id_modulo']; ?>"><?php echo $row['nombre_modulo']; ?></option>
                                                    <?php
                                                    }
                                                    $con->desconectar_bd($bd);
                                                }
                                        ?>
                                        </select>
                                    </div>
                                </form>
                                <script type="text/javascript">
                                    // Change the selector if needed
                                var $table = $('table.scroll'),
                                    $bodyCells = $table.find('tbody tr:first').children(),
                                    colWidth;

                                // Adjust the width of thead cells when window resizes
                                $(window).resize(function() {
                                    // Get the tbody columns width array
                                    colWidth = $bodyCells.map(function() {
                                        return $(this).width();
                                    }).get();
                                    
                                    // Set the width of thead columns
                                    $table.find('thead tr').children().each(function(i, v) {
                                        $(v).width(colWidth[i]);
                                    });    
                                }).resize(); // Trigger resize handler
                </script>
            </article>
        </section>
    </body>
</html>